package com.ruoyi.common.utils;

import javax.servlet.http.HttpServletRequest;

public class OtherUtils {

    public static String getServerUrl(HttpServletRequest request){
        // 访问协议
        String agreement = request.getScheme();
        // 访问域名
        String serverName = request.getServerName();
        // 访问端口号
        int port = request.getServerPort();
        // 访问项目名
        String contextPath = request.getContextPath();
        String url = "%s://%s%s%s/";
        String portStr = "";
        if (port != 80) {
            portStr += ":" + port;
        }
        String format = String.format(url, agreement, serverName, portStr, contextPath);
        return format;
    }
}
